package com.pub.dbtools;

import java.util.ArrayList;

public class DataDtoSupclass {

	public static final String getDataValue(ArrayList arraydata, String name,
			int recordno) {
		String[] tmparr = (String[]) arraydata.get(0);
		int realnum = -1;
		for (int s = 0; s < tmparr.length; s++) {
			String tmpstr = tmparr[s];
			tmpstr = tmpstr.toLowerCase();
			if (tmpstr.equals(name.toLowerCase())) {
				realnum = s;
				break;
			}
		}
		if (realnum > -1) {
			tmparr = (String[]) arraydata.get(recordno + 1);
			String valuestr = tmparr[realnum];

			if (valuestr.endsWith(".000000") || valuestr.endsWith(".00000")
					|| valuestr.endsWith(".0000") || valuestr.endsWith(".000")
					|| valuestr.endsWith(".00") || valuestr.endsWith(".0")
					|| valuestr.endsWith(".")) {
				return valuestr.substring(0, valuestr.lastIndexOf(".") );
			}

			return valuestr;
		} else {
			return "无此字段内容!";
		}
	}

	public static final String getDataValue(ArrayList arraydata, int fieldno,
			int recordno) {
		String[] tmparr = (String[]) arraydata.get(0);
		tmparr = (String[]) arraydata.get(recordno + 1);
		String valuestr = tmparr[fieldno];

		if (valuestr.endsWith(".000000") || valuestr.endsWith(".00000")
				|| valuestr.endsWith(".0000") || valuestr.endsWith(".000")
				|| valuestr.endsWith(".00") || valuestr.endsWith(".0")
				|| valuestr.endsWith(".")) {
			return valuestr.substring(0, valuestr.lastIndexOf(".") );
		}

		return valuestr;
	}

	public static final ArrayList setDataValue(ArrayList arraydata,
			String name, int recordno, String newvalue) {

		String[] tmparr = (String[]) arraydata.get(0);
		int realnum = -1;
		for (int s = 0; s < tmparr.length; s++) {
			String tmpstr = tmparr[s];
			tmpstr = tmpstr.toLowerCase();

			if (tmpstr.equals(name.toLowerCase())) {
				realnum = s;
				break;
			}
		}
		if (realnum > -1) {
			tmparr = (String[]) arraydata.get(recordno + 1);
			tmparr[realnum] = newvalue;
			arraydata.set(recordno + 1, tmparr);
		}
		return arraydata;
	}

	public static final ArrayList setDataValue(ArrayList arraydata,
			int fieldno, int recordno, String newvalue) {
		String[] tmparr = (String[]) arraydata.get(0);
		int realnum = 0;
		tmparr = (String[]) arraydata.get(recordno + 1);
		tmparr[recordno] = newvalue;
		arraydata.set(recordno + 1, tmparr);
		return arraydata;
	}

}
